import React, { Component } from 'react'
import {ListBox} from '../../../components'
import UpdateWorkareaPage from './UpdateNew'
import UpdateWorkareaPageUp from './UpdateNewUp'

import {fetchData} from '../../../components/AjaxConsumer'
import {  Button, Modal, Form, Input, Radio,Upload, Icon } from 'antd';
export default class ListProOrderInSnPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            tableColumn: {},
            searchComponentData: [],
            visible: false,
        };
        //行操作列表
        this.rowOperation = [
            {
                handleName: 'edit',
                iconClass: 'cellEdit'
            }, {
                handleName: 'delete',
                iconClass: 'cellDele'
            }, {
                handleName: 'assignUser',
                iconClass: 'cellRole'
            }
        ];
        //header 操作列表
        this.headerOperation = [
            //{
            //    handleName: 'add',
            //    showName: '新增',
            //    iconClass: 'plus',
            //    permission: 'rawbarcode-add'
            //},{
            //    handleName: 'edit',
            //    showName: '修改',
            //    iconClass: 'edit',
            //    permission: 'rawbarcode-edit'
            //}
            //,{
            //    handleName: 'delete',
            //    showName: '删除',
            //    iconClass: 'delete',
            //    permission: 'rawbarcode-del'
            //},{
            //    handleName: 'upload',
            //    showName: '打印',
            //    iconClass: 'upload',
            //    permission: 'rawbarcode-print'
            //}
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        this.tableColumn = {
            storageKey: 'orderInSnId',
            data: [
                {
                    showName: '批次号',
                    columnName: 'userDefined2',
                    columnWidth: 120
                }
                ,{
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 110
                },
                {
                    showName: '型号',
                    columnName: 'model',
                    columnWidth: 120
                },
                {
                    showName: '品名',
                    columnName: 'productName',
                    columnWidth: 90
                },{
                    showName: '定量',
                    columnName: 'density',
                  columnWidth: 90
                },
                {
                    showName: '规格',
                    columnName: 'spec',
                    columnWidth: 90
                }, {
                    showName: '生产机号',
                    columnName: 'machineNumber',
                    columnWidth: 110,
                    showOption:[
                        {
                            optionKey: 2,
                            optionShow:'2号机'
                        },{
                            optionKey: 4,
                            optionShow:'4号机'
                        }
                    ]
                }, {
                    showName: '等级',
                    columnName: 'grade',
                    columnWidth: 90,
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'1',
                            optionShow:'一等品'
                        },{
                            optionKey:'2',
                            optionShow:'二等品'
                        },{
                            optionKey:'3',
                            optionShow:'处理品'
                        }
                    ]
                }, {
                    showName: '级别',
                    columnName: 'level',
                    columnWidth: 90,
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'A',
                            optionShow:'A'
                        },{
                            optionKey:'B',
                            optionShow:'B'
                        },{
                            optionKey:'C',
                            optionShow:'C'
                        }
                    ]
                }, {
                    showName: '类型',
                    columnName: 'type',
                    columnWidth: 90,
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'0',
                            optionShow:'正品'
                        },{
                            optionKey:'1',
                            optionShow:'样品'
                        }
                    ]
                },{
                    showName: '打印状态',
                    columnName: 'status',
                    columnWidth: 110,
                    showOption:[
                        {
                            optionKey:'',
                            optionShow:''
                        },{
                            optionKey:'0',
                            optionShow:'未打印'
                        },{
                            optionKey:'1',
                            optionShow:'已打印'
                        }
                    ]
                },{
                    showName: '入库状态',
                    columnName: 'userDefined1',
                    columnWidth: 110,
                    showOption:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未入库'
                    },{
                        optionKey:'1',
                        optionShow:'已入库'
                    }
                ]
                },{
                    showName: '下线时间',
                    columnName: 'gmtCreate',
                    columnWidth: 140
                }
                // {
                //     showName: '登记表主键',
                //     columnName: 'userDefined3',
                //   //columnWidth: 140
                // },{
                //     showName: '供应商代码',
                //     columnName: 'userDefined4',
                //   //columnWidth: 140
                // },{
                //     showName: '供应商名称',
                //     columnName: 'userDefined5',
                //   //columnWidth: 140
                // },{
                //     showName: '是否合格',
                //     columnName: 'userDefined6',
                //     columnWidth: 100,
                //   showOption:[
                //     {
                //         optionKey:'',
                //         optionShow:''
                //     },{
                //         optionKey:'0',
                //         optionShow:'不合格'
                //     },{
                //         optionKey:'1',
                //         optionShow:'合格'
                //     }
                // ]
                // },{
                //     showName: '不合格原因',
                //     columnName: 'userDefined7',
                //     columnWidth: 140
                // }
            ]
        };

        //搜索属性配置
        this.searchComponentData = [
            {
                showName: '等级',
                name: 'grade',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'1',
                        optionShow:'一等品'
                    },{
                        optionKey:'2',
                        optionShow:'二等品'
                    },{
                        optionKey:'3',
                        optionShow:'处理品'
                    }
                ]
            },{
                showName: '级别',
                name: 'level',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'A',
                        optionShow:'A'
                    },{
                        optionKey:'B',
                        optionShow:'B'
                    },{
                        optionKey:'C',
                        optionShow:'C'
                    }
                ]
            },{
                showName: '类型',
                name: 'type',
                type: 'select',
                optionList:[
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'正品'
                    },{
                        optionKey:'1',
                        optionShow:'样品'
                    }
                ]
            },{
                showName: '下线时间',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            },{
                showName: '打印状态',
                name:'status',
                type: 'select',
                optionList:[//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未打印'
                    },{
                        optionKey:'1',
                        optionShow:'已打印'
                    }
                ]
            },{
                showName: '入库状态',
                name:'userDefined1',
                type: 'select',
                optionList:[//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'未入库'
                    },{
                        optionKey:'1',
                        optionShow:'已入库'
                    }
                ]
            },{
                showName: '是否合格',
                name:'userDefined6',
                type: 'select',
                optionList:[//下拉框的信息
                    {
                        optionKey:'',
                        optionShow:''
                    },{
                        optionKey:'0',
                        optionShow:'不合格'
                    },{
                        optionKey:'1',
                        optionShow:'合格'
                    }
                ]
            },
            {
                showName: '生产机号',
                name:'machineNumber',
                type: 'select',
                // optionList:[]
                url:'/base/dic/get/machine_number'
            }
        ];

    }

    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if (strHandles === 'edit') {
            this.editHandle(rowObj);
        } else if (strHandles === 'delete') {
            this.deleteHandle(rowObj);
        } else if (strHandles === 'add') {
            this.addHandle();
        } else if (strHandles == 'upload') {
            this.upload();
        }
    }
    // 增加工作区
    addHandle = () => {
        console.log("====执行了新增工作区操作====");
        this.refs.updateWorkarea.addWorkareaHandle();
    }

    // 上传
    upload = () => {
        console.log("====执行了上传操作====");
                //    this.setState({ visible: true });
        this.refs.updateWorkareaUp.add();
                


    }
    editHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateWorkarea.editHandle(rowObj[0].data);
        }
    }

    deleteHandle = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else if(rowObj.length > 1){
            Modal.error({
                title: '错误提示',
                content: '只能选择一条数据',
            });
        }else{
            this.refs.updateWorkarea.deleteHandle(rowObj[0].data)
        }
    }
    // 给区域分配角色
    assignFactoryUserHandle = (rowObj) => {
        let workareaId = rowObj.workareaId;
        this.refs.assignFactoryUser.initModal(workareaId);
    }


    //刷新列表
    refreshHandle = () => {
        this.refs.listWorkarea.refreshHandle();
    }

    // componentWillMount() {
    //     const dicType = 'model_type_p';
    //     const options= {
    //         url: '/base/dic/get/' + dicType,
    //         type: 'get',
    //         condition:{}
    //     };
    //     //先写死，后面再改
    //     fetchData(this, options, this.dicInitCallBackHandle);
    // }

    // //下拉框 初始化
    // dicInitCallBackHandle = (resData)=>{
    //     //alert('resData' + JSON.stringify(resData, null, 4));
    //     let optionList = [];
    //     let tmp = {};
    //     tmp.optionKey = '';
    //     tmp.optionShow = '';
    //     optionList.push(tmp);
    //     resData.data.map( (e,index) => {
    //         let tmp = {};
    //         tmp.optionKey = e.dicCode;
    //         tmp.optionShow = e.dicName;
    //         optionList.push(tmp);
    //     });

    //     //alert('optionList' + JSON.stringify(optionList, null, 4));
    //     this.tableColumn.data[3].showOption = optionList;
    //     this.searchComponentData[0].optionList = optionList;
    // }

  handleCancel = () => {
    this.setState({ visible: false });
      this.form.resetFields();
    
  }
  handleCreate = () => {
    const form = this.form;
    form.validateFields((err, values) => {
      if (err) {
        return;
      }

      console.log('Received values of form: ', values);
      form.resetFields();
      this.setState({ visible: false });
    });
  }
  saveFormRef = (form) => {
    this.form = form;
  }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return (
            <div>
                <ListBox
                    ref='listWorkarea'
                    title="成品下线明细"
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/product/probarcode/list'
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />

                <UpdateWorkareaPage
                    ref="updateWorkarea"
                    refreshHandle={this.refreshHandle}
                />
                 <UpdateWorkareaPageUp
                    ref="updateWorkareaUp"
                    refreshHandle={this.refreshHandle}
                /> 
            
            </div>
        )
    }
}
